home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / gray2clr.c < prev    next >
C/C++ Source or Header  |  1994-07-18  |  3KB  |  94 lines

  1. /*****************************************************************
  2.  * gray2clr.c: FBM Release 1.2 07-Apr-93 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989-1993 by Michael Mauldin.  Permission is granted
  5.  * to use this file in whole or in part for any purpose, educational,
  6.  * recreational or commercial, provided that this copyright notice
  7.  * is retained unchanged.  This software is available to all free of
  8.  * charge by anonymous FTP and in the UUNET archives.
  9.  *
  10.  * gray2clr.c: 
  11.  *
  12.  * USAGE
  13.  *    % gray2clr [ flags ] arguments
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:18:17 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/gray2clr.c
  18.  *
  19.  * HISTORY
  20.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  21.  *    Added -J switch
  22.  *
  23.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  24.  *    Package for Release 1.0
  25.  *
  26.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  27.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  28.  *
  29.  *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  30.  *    Created.
  31.  *****************************************************************/
  32.  
  33. # include <stdio.h>
  34. # include <math.h>
  35. # include "fbm.h"
  36.  
  37. # define USAGE "gray2clr [ -<type> ] [ -u ] < gray > color"
  38.  
  39. #ifndef lint
  40. static char *fbmid =
  41. "$FBM gray2clr.c <1.2> 07-Apr-93 (C) 1989-1993 by Michael Mauldin, source \
  42. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  43. #endif
  44.  
  45. main (argc, argv)
  46. char *argv[];
  47. { FBM input, output;
  48.   int outtype = DEF_8BIT;
  49.   int mapped = 1;
  50.  
  51.   /* If invoked as 'unmap', set option to mapped=0 */
  52.   if (strcmp (argv[0] + strlen (argv[0]) - 5, "unmap") == 0)
  53.   { mapped = 0; }
  54.  
  55.   /* Get the options */
  56.   while (--argc > 0 && (*++argv)[0] == '-')
  57.   { while (*++(*argv))
  58.     { switch (**argv)
  59.       { case 'u':    mapped = 0; break;
  60.     case 'A':    outtype = FMT_ATK; break;
  61.     case 'B':    outtype = FMT_FACE; break;
  62.     case 'F':    outtype = FMT_FBM; break;
  63.     case 'G':    outtype = FMT_GIF; break;
  64.     case 'I':    outtype = FMT_IFF; break;
  65.     case 'J':    outtype = FMT_JPEG; break;
  66.     case 'L':    outtype = FMT_LEAF; break;
  67.     case 'M':    outtype = FMT_MCP; break;
  68.     case 'P':    outtype = FMT_PBM; break;
  69.     case 'R':    outtype = FMT_RLE; break;
  70.     case 'S':    outtype = FMT_SUN; break;
  71.     case 'T':    outtype = FMT_TIFF; break;
  72.     case 'X':    outtype = FMT_X11; break;
  73.     case 'Z':    outtype = FMT_PCX; break;
  74.     default:        fprintf (stderr, "%s\n", USAGE);
  75.                         exit (1);
  76.       }
  77.     }
  78.   }
  79.  
  80.   /* Clear the memory pointers so alloc_fbm won't be confused */
  81.   input.cm  = input.bm  = (unsigned char *) NULL;
  82.   output.cm = output.bm = (unsigned char *) NULL;
  83.  
  84.   /* Read the image and convert it */
  85.   if (read_bitmap (&input, (char *) NULL) &&
  86.       (mapped ?
  87.        gray2clr (&input, &output, outtype == FMT_SUN) :
  88.        clr_unmap (&input, &output)) &&
  89.       write_bitmap (&output, stdout, outtype))
  90.   { exit (0); }
  91.  
  92.   exit (1);
  93. }
  94.